home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 476-500 / disk_483 / pwkeys / pwkeys.asm < prev    next >
Assembly Source File  |  1992-05-06  |  32KB  |  1,213 lines

  1. *    PWKeys V1.0
  2. *    By Preben Nielsen
  3. *
  4. *      PWKeys is an input-handler that allows you to manipulate windows
  5. *    and screens by pressing keys on the keyboard (a lot faster than
  6. *    using the mouse).
  7. *
  8. *      Once installed, the program only uses 1124 bytes of memory. To
  9. *    remove PWKeys simply run the it again.
  10. *
  11. *    NOTE:    There's no need to 'RUN' or 'RUNBACK' this program from the
  12. *        CLI. It terminates immediately.
  13. *
  14. *HISTORY
  15. *          Made with Hisoft V2.12
  16. *
  17. *  V1.0   20-Apr-91: This is first release. I made it over a year ago
  18.  
  19.     OPT O+
  20.     OPT O1+            ; Tells when a branch could be optimised to short
  21.     OPT i+            ; Tells when '#' is probably missing
  22.         include        "PWKeys.i"
  23.         incdir        "AsmInc:"
  24.         include        "exec/exec_lib.i"
  25.         include        "exec/io.i"
  26.         include        "exec/memory.i"
  27.         include        "exec/interrupts.i"
  28.         include        "devices/input.i"
  29.         include        "devices/inputevent.i"
  30.         include        "libraries/dos.i"
  31.         include        "libraries/dos_lib.i"
  32.         include        "libraries/dosextens.i"
  33.         include        "graphics/layers.i"
  34.         include        "intuition/intuition.i"
  35.         include        "intuition/intuitionbase.i"
  36.         include        "intuition/intuition_lib.i"
  37.         include        "Workbench/startup.i"
  38.         include        "Workbench/workbench.i"
  39.         include        "Workbench/icon_lib.i"
  40.  
  41.  
  42. Prepare        MACRO
  43.         IFC        '\1','Exec_Call'
  44.         movea.l        4.W,A6
  45.         ENDC
  46.         IFC        '\1','Icon_Call'
  47.         movea.l        IconBase(DB),A6
  48.         ENDC
  49.         IFC        '\1','Intuition_Call'
  50.         movea.l        IntBase(DB),A6
  51.         ENDC
  52.         IFC        '\1','Gfx_Call'
  53.         movea.l        GfxBase(DB),A6
  54.         ENDC
  55.         IFC        '\1','Dos_Call'
  56.         movea.l        DosBase(DB),A6
  57.         ENDC
  58.         ENDM
  59. CallLib        MACRO
  60.         jsr        _LVO\1(A6)
  61.         ENDM
  62. Call        MACRO
  63.         bsr        \1
  64.         ENDM
  65. CallS        MACRO
  66.         bsr.S        \1
  67.         ENDM
  68. Push        MACRO
  69.         movem.l        \1,-(SP)
  70.         ENDM
  71. Pop        MACRO
  72.         movem.l        (SP)+,\1
  73.         ENDM
  74. rAPtr        MACRO        name
  75. DefSiz        set        DefSiz+4
  76. DefPtr        set        DefPtr-4
  77. \1        =        DefPtr
  78.         ENDM
  79. rLong        MACRO        name
  80. DefSiz        set        DefSiz+4
  81. DefPtr        set        DefPtr-4
  82. \1        =        DefPtr
  83.         ENDM
  84. rWord        MACRO        name
  85. DefSiz        set        DefSiz+2
  86. DefPtr        set        DefPtr-2
  87. \1        =        DefPtr
  88.         ENDM
  89. rByte        MACRO        name
  90. DefSiz        set        DefSiz+1
  91. DefPtr        set        DefPtr-1
  92. \1        =        DefPtr
  93.         ENDM
  94. rStorage    MACRO        name,size    ; Define storage
  95. DefSiz        set        DefSiz+\2
  96. DefPtr        set        DefPtr-\2
  97. \1        =        DefPtr
  98.         ENDM
  99. rEVEN        MACRO                ; Word boundary
  100.         IFNE        DefPtr&1
  101. DefPtr        set        DefPtr-1
  102. DefSiz        set        DefSiz+1
  103.         ENDC
  104.         ENDM
  105. rStart        MACRO                ; Define var section
  106. DefPtr        set        0
  107. DefSiz        set        0
  108.         ENDM
  109. rEnd        MACRO                ; End var section
  110. RelSize        =        DefSiz
  111.         ENDM
  112. rAlloc        MACRO                ; Allocate vars
  113.         link        DB,#-RelSize
  114.         ENDM
  115. rFree        MACRO                ; Deallocate vars
  116.         unlk        DB
  117.         ENDM
  118. rClear        MACRO                ; Reset all vars
  119.         movem.l        D0/DB,-(SP)
  120.         move.w        #RelSize-1,D0
  121. rClr.\@        clr.b        -(DB)
  122.         dbf        D0,rClr.\@
  123.         movem.l        (SP)+,D0/DB
  124.         ENDM
  125.  
  126. DB        EQUR        A4
  127.  
  128.         SECTION        PWKeys,CODE
  129. InitProcess    rAlloc                    ; Allocate memory for variables
  130.         rClear                    ; Clear the memory
  131.         subq.l        #1,D0
  132.         move.l        A0,CName(DB)
  133.         move.l        D0,CLen(DB)
  134.         Prepare        Exec_Call
  135.         CallLib        Forbid
  136.         lea        IHS(PC),A1
  137.         lea        ihs_PortName(A1),A1
  138.         CallLib        FindPort
  139.         move.l        D0,HPort(DB)
  140.         CallLib        Permit
  141.         suba.l        A1,A1
  142.         CallLib        FindTask        ; Find us
  143.         move.l        D0,PProcess(DB)
  144.         movea.l        D0,A2
  145.         tst.l        pr_CLI(A2)
  146.         bne.S        CLIStart
  147. WBStart        lea        pr_MsgPort(A2),A0
  148.         CallLib        WaitPort        ; wait for a message
  149.         lea        pr_MsgPort(A2),A0
  150.         CallLib        GetMsg            ; then get it
  151.         move.l        D0,WBMsg(DB)        ; save it for later reply
  152.         bra.S        GetLibs
  153. CLIStart    move.l        CName(DB),A0
  154.         move.l        CLen(DB),D0
  155.         clr.b        0(A0,D0.W)
  156. GetLibs        lea        DosName(PC),A1
  157.         CallLib        OldOpenLibrary
  158.         move.l        D0,DosBase(DB)
  159.         beq        Error
  160.         lea        IntName(PC),A1
  161.         CallLib        OldOpenLibrary
  162.         move.l        D0,IntBase(DB)
  163.         beq        Error
  164.  
  165.         tst.l        HPort(DB)        ;Install or Remove ?
  166.         bne.S        LetsBegin
  167.         tst.l        WBMsg(DB)
  168.         beq.S        LetsBegin        ;CLI or WB ?
  169.  
  170.         clr.l        CLen(DB)        ;Signal that we haven't found args yet
  171.         move.l        WBMsg(DB),A2
  172.         move.l        sm_NumArgs(A2),D0    ;Any args ?
  173.         move.l        sm_ArgList(A2),A2
  174.         subq.l        #1,D0
  175.         blt.S        LetsBegin
  176.         beq.S        FoundArg
  177.         addq.w        #wa_SIZEOF,A2        ;Project
  178. FoundArg    move.l        wa_Lock(A2),D1
  179.         move.l        wa_Name(A2),A2        ;Name of icon
  180.         beq.S        NoLock
  181.         Prepare        Dos_Call
  182.         CallLib        CurrentDir
  183. NoLock        Prepare        Exec_Call
  184.         lea        IconName(PC),A1
  185.         CallLib        OldOpenLibrary
  186.         move.l        D0,IconBase(DB)
  187.         beq.S        LetsBegin
  188.         Prepare        Icon_Call
  189.         move.l        A2,A0
  190.         CallLib        GetDiskObject        ;Get the icon
  191.         move.l        D0,DiskObj(DB)
  192.         beq.S        LetsBegin
  193.         move.l        D0,A2
  194.         move.l        do_ToolTypes(A2),A0
  195.         lea        FileTxt(PC),A1
  196.         CallLib        FindToolType        ;Find 'FILE=??????'
  197.         move.l        D0,CName(DB)
  198.         move.l        D0,CLen(DB)        ;Signal that we have or haven't found args
  199. LetsBegin    tst.l        HPort(DB)
  200.         beq.S        DoInstall
  201. DoRemove    moveq        #REMOVED,D7
  202.         lea        IHS(PC),A0
  203.         lea        PSEndIHS1(PC),A1
  204.         lea        PSEndIHS2(PC),A2
  205.         Call        RemoveHandler
  206.         beq.S        ShowMsg
  207.         moveq        #CANTREMOVE,D7
  208.         bra.S        ShowMsg
  209. DoInstall    moveq        #INSTALLED,D7
  210.         lea        IHS(PC),A0
  211.         lea        PSPrepIHS1(PC),A1
  212.         lea        PSPrepIHS2(PC),A2
  213.         Call        InstallHandler
  214.         beq.S        ShowMsg
  215.         moveq        #CANTINSTALL,D7
  216. ShowMsg        move.l        D7,D0
  217.         Call        CONMsg
  218.  
  219. Error
  220. Exit        Prepare        Exec_Call
  221. FreeDos        move.l        DosBase(DB),D0
  222.         beq.S        ReplyWB
  223.         move.l        D0,A1
  224.         CallLib        CloseLibrary
  225. ReplyWB        move.l        WBMsg(DB),D0
  226.         beq.S        AllDone
  227.         move.l        DiskObj(DB),D0
  228.         beq.S        FreeIcon
  229.         move.l        D0,A0
  230.         Prepare        Icon_Call
  231.         CallLib        FreeDiskObject
  232. FreeIcon    Prepare        Exec_Call
  233.         move.l        IconBase(DB),D0
  234.         beq.S        WBEnd
  235.         move.l        D0,A1
  236.         CallLib        CloseLibrary
  237. WBEnd        CallLib        Forbid            ; We were started from WB
  238.         move.l        WBMsg(DB),A1
  239.         CallLib        ReplyMsg        ; Reply WBMessage
  240. AllDone        rFree
  241.         moveq        #0,D0
  242.         rts
  243.  
  244.  
  245. FHandle        EQUR        D5
  246. * Call: D0 = Msg-number
  247. CONMsg        Push        D0-D7/A0-A6
  248.         Prepare        Dos_Call
  249.         move.l        D0,D4
  250.         moveq        #0,D6
  251.         CallLib        Output
  252.         move.l        D0,FHandle
  253.         bne.S        1$
  254.         moveq        #1,D6
  255.         lea        CONName(PC),A0
  256.         move.l        A0,D1
  257.         move.l        #MODE_OLDFILE,D2
  258.         CallLib        Open
  259.         move.l        D0,FHandle
  260.         beq.S        2$
  261. 1$        moveq        #INFOMSG,D0
  262.         Call        SendMsg
  263.         move.l        D4,D0
  264.         Call        SendMsg
  265.         tst.l        D6
  266.         beq.S        2$
  267.         moveq        #127,D1
  268.         CallLib        Delay
  269.         move.l        FHandle,D1
  270.         CallLib        Close
  271. 2$        Pop        D0-D7/A0-A6
  272.         rts
  273.  
  274. * Call: D0 = Msg-number
  275. SendMsg        neg.l        D0
  276.         lsl.l        #1,D0
  277.         lea        MsgTable(PC),A0
  278.         add.w        0(A0,D0),A0
  279.         move.l        A0,D2
  280.         moveq        #-1,D3
  281. 1$        addq.l        #1,D3
  282.         tst.b        (A0)+
  283.         bne.S        1$
  284.         move.l        FHandle,D1
  285.         Prepare        Dos_Call
  286.         CallLib        Write
  287.         rts
  288.  
  289. INFOMSG        =0
  290. INSTALLED    =-1
  291. REMOVED        =-2
  292. CANTINSTALL    =-3
  293. CANTREMOVE    =-4
  294.  
  295. MsgText        MACRO
  296.         dc.w        \1-MsgTable
  297.         ENDM
  298. MsgTable    MsgText        Msg
  299.         MsgText        Msg1
  300.         MsgText        Msg2
  301.         MsgText        Msg3
  302.         MsgText        Msg4
  303.  
  304. CONName        dc.b        'CON:100/60/330/63/PWKeys',0
  305. Msg        dc.b        10,$9B,'0;33m PWKeys V1.0',10
  306.         dc.b        $9B,'0;31m 1991 by ',$9B,'0;33mPreben Nielsen',$9B,'0;31m',10,' ',0
  307. Msg1        dc.b        'has just been installed...',10,0
  308. Msg2        dc.b        'has just been removed...',10,0
  309. Msg3        dc.b        'Error: Cannot install handler',10,0
  310. Msg4        dc.b        'Error: Cannot remove handler',10,0
  311.         EVEN
  312.  
  313. rtsValue    EQUR        D7
  314. * This is general-purpose inputhandler removal-routine
  315. * It only needs an ihs with a port-name to remove the handler
  316. * Call:   A0 = ihs
  317. *      A1 = first ihs-installation-routine or NULL
  318. *      A2 = second ihs-installation-routine or NULL
  319. * Return: D0 = 0 means succes
  320. RemoveHandler    Push        D1/rtsValue/A0-A3/A6
  321.         moveq        #-1,rtsValue
  322.         move.l        A2,A3
  323.         move.l        A0,A2
  324.         move.l        A1,D1
  325.         beq.S        1$
  326.         jsr        (A1)        ; A0 = ihs
  327.         beq.S        2$
  328.         move.l        D0,A2
  329. 1$        move.l        A2,A0
  330.         Prepare        Exec_Call
  331.         moveq        #IND_REMHANDLER,D0
  332.         Call        TellInputDevice
  333.         move.l        D0,rtsValue
  334.         bne.S        2$
  335.         lea        ihs_Port(A2),A1
  336.         CallLib        RemPort
  337.         moveq        #0,D0
  338.         bra.S        3$
  339. 2$        moveq        #-1,D0
  340. 3$        move.l        A3,D1
  341.         beq.S        4$
  342.         move.l        A2,A0
  343.         jsr        (A3)        ; A0 = ihs, D0 = 0 means succes
  344. 4$        move.l        rtsValue,D0
  345.         Pop        D1/rtsValue/A0-A3/A6
  346.         rts
  347.  
  348. * This is general-purpose inputhandler installation-routine
  349. * It only needs an ihs with a port-name to install the handler
  350. * Call:   A0 = ihs
  351. *      A1 = first ihs-installation-routine or NULL
  352. *      A2 = second ihs-installation-routine or NULL
  353. * Return: D0 = 0 means succes
  354. InstallHandler    Push        D1/rtsValue/A0-A3/A6
  355.         moveq        #-1,rtsValue
  356.         move.l        A2,A3
  357.         move.l        A0,A2
  358.         move.l        A1,D1
  359.         beq.S        1$
  360.         jsr        (A1)        ; A0 = ihs
  361.         beq.S        2$
  362.         move.l        D0,A2
  363. 1$        move.l        A2,A0
  364.         moveq        #IND_ADDHANDLER,D0
  365.         Call        TellInputDevice
  366.         move.l        D0,rtsValue
  367.         bne.S        2$
  368.         lea        ihs_Port(A2),A1
  369.         lea        ihs_PortName(A2),A0
  370.         move.l        A0,MP+LN_NAME(A1)        ;MsgPort->mp_Node.ln_Name=Name;
  371.         clr.b        MP+LN_PRI(A1)            ;MsgPort->mp_Node.ln_Pri =0;
  372.         move.b        #NT_MSGPORT,MP+LN_TYPE(A1)    ;MsgPort->mp_Node.ln_Type=NT_MSGPORT;
  373.         move.b        #PA_IGNORE,MP_FLAGS(A1)        ;MsgPort->mp_Flags     =PA_IGNORE;
  374.         Prepare        Exec_Call
  375.         CallLib        AddPort
  376.         moveq        #0,D0
  377.         bra.S        3$
  378. 2$        moveq        #-1,D0
  379. 3$        move.l        A3,D1
  380.         beq.S        4$
  381.         move.l        A2,A0
  382.         jsr        (A3)        ; A0 = ihs, D0 = 0 means succes
  383. 4$        move.l        rtsValue,D0
  384.         Pop        D1/rtsValue/A0-A3/A6
  385.         rts
  386.  
  387. * Open the input device. Set up the I/O block to add or remove the
  388. * input handler, and send the request to the input device. Finally,
  389. * close the device
  390. * Call:   A0 = ihs
  391. *      D0 = Function to perform (IND_ADDHANDLER/IND_REMHANDLER)
  392. * Return: D0 = 0 means succes
  393. TellInputDevice    Push        D1-D2/rtsValue/A0-A3/A6
  394.         Prepare        Exec_Call
  395.         moveq        #-1,rtsValue
  396.         move.l        D0,D2
  397.         move.l        A0,A2
  398.         lea        IReq(DB),A0
  399.         moveq        #IOSTD_SIZE,D0
  400.         Call        MemClear
  401.         lea        IPort(DB),A0
  402.         moveq        #MP_SIZE,D0
  403.         Call        MemClear
  404.         move.l        A0,A3
  405.         move.b        #NT_MSGPORT,MP+LN_TYPE(A3)    ; mp_Node.ln_Type=NT_MSGPORT;
  406.         move.b        #PA_SIGNAL,MP_FLAGS(A3)        ; mp_Flags    =PA_SIGNAL;
  407.         moveq        #-1,D0
  408.         CallLib        AllocSignal
  409.         move.b        D0,MP_SIGBIT(A3)        ; mp_SigBit    =MPSigBit;
  410.         bmi.S        2$
  411.         suba.l        A1,A1
  412.         CallLib        FindTask
  413.         move.l        D0,MP_SIGTASK(A3)        ; mp_SigTask     =FindTask(0);
  414.         lea        IReq(DB),A1
  415.         move.l        A3,IO+MN_REPLYPORT(A1)        ; ExtReq->io_Message.mn_ReplyPort   =taskReplyPort;
  416.         move.b        #NT_MESSAGE,IO+MN+LN_TYPE(A1)    ; ExtReq->io_Message.mn_Node.ln_Type=NT_MESSAGE;
  417.         lea        InputName(PC),A0        ; input.device
  418.         moveq        #0,D0                ; unit#
  419.         moveq        #0,D1                ; flags
  420.         CallLib        OpenDevice
  421.         tst.w        D0                ; flag: error if > 0
  422.         bne.S        1$
  423.         lea        IReq(DB),A1
  424.         move.w        D2,IO_COMMAND(A1)
  425.         lea        ihs_Interrupt(A2),A0
  426.         move.l        A0,IO_DATA(A1)
  427.         CallLib        DoIO
  428.         move.l        D0,rtsValue
  429.         lea        IReq(DB),A1
  430.         CallLib        CloseDevice
  431. 1$        move.b        MP_SIGBIT(A3),D0
  432.         CallLib        FreeSignal
  433. 2$        move.l        rtsValue,D0
  434.         Pop        D1-D2/rtsValue/A0-A3/A6
  435.         rts
  436.  
  437. * Call: A0    = Memory area
  438. *    D0:16 = Count
  439. MemClear    Push        D0-D1/A0
  440.         moveq        #0,D1
  441.         bra.S        2$
  442. 1$        move.b        D1,(A0)+
  443. 2$        dbf        D0,1$
  444.         Pop        D0-D1/A0
  445.         rts
  446.  
  447. * Call: A0   = Source
  448. *    A1   = Destination
  449. *    D0:16= Count
  450. MemCopy        Push        D0/A0-A1
  451.         bra.S        2$
  452. 1$        move.b        (A0)+,(A1)+
  453. 2$        dbf        D0,1$
  454.         Pop        D0/A0-A1
  455.         rts
  456.  
  457.  
  458. * Each handler should have such a pair of installation-routine
  459. * The first one is passed to InstallHandler in A1 and it
  460. * is called immediately when entering InstallHandler
  461. * The second one is passed to InstallHandler in A2 and it
  462. * is called after attempt to install handler and message-port
  463. * -----------------------------------------------------------------
  464. * Call:   A0 = ihs
  465. * Return: D0 has to point to ihs to be used when installation proceeds
  466. *      If D0 = 0 then installation is aborted
  467. PSPrepIHS1    Push        D1/A0-A1/A6
  468.         Call        GetKeys
  469.         beq.S        2$
  470.         lea        IntuiBase(PC),A1
  471.         move.l        IntBase(DB),(A1)
  472.         Prepare        Exec_Call
  473.         move.l        #HandlerSize,D0
  474.         move.l        #MEMF_PUBLIC|MEMF_CLEAR,D1
  475.         CallLib        AllocMem
  476.         move.l        D0,HMem(DB)
  477.         beq.S        2$
  478.         move.l        D0,A1
  479.         lea        IHS(PC),A0
  480.         move.l        #HandlerSize,D0
  481.         Call        MemCopy
  482.         move.l        D0,ihs_Length(A1)        ; This will enable removal by other programs
  483.         lea        HandlerCode-IHS(A1),A0
  484.         move.l        A0,ihs_Interrupt+IS_CODE(A1)    ; HandlerBlock.HInterrupt.is_Code = Handler
  485.         lea        PWKVersionID-IHS(A1),A0
  486.         move.l        A0,ihs_Interrupt+IS_DATA(A1)    ;HandlerBlock.HInterrupt.is_Data = KeyDefines;
  487.         move.b        PWKPri(PC),ihs_Interrupt+LN_PRI(A1);HandlerBlock.HInterrupt.is_Node.ln_Pri = PRI;
  488.         move.l        A1,D0
  489. 2$        Pop        D1/A0-A1/A6
  490.         rts
  491. * Call:   A0 = ihs
  492. *         D0 = 0 means everything went perfect
  493. *             -1 means something went wrong during installation
  494. PSPrepIHS2    Push        D0-D1/A0-A1/A6
  495.         tst.l        D0
  496.         beq.S        1$
  497.         move.l        HMem(DB),D0
  498.         beq.S        1$
  499.         move.l        D0,A1
  500.         move.l        #HandlerSize,D0
  501.         Prepare        Exec_Call
  502.         CallLib        FreeMem
  503. 1$        Pop        D0-D1/A0-A1/A6
  504.         rts
  505.  
  506. * Each handler should have such a pair of ending-routine
  507. * The first one is passed to RemoveHandler in A1 and it
  508. * is called immediately when entering RemoveHandler
  509. * The second one is passed to RemoveHandler in A2 and it
  510. * is called after attempt to remove handler and message-port
  511. * -----------------------------------------------------------------
  512. * Call:   A0 = ihs
  513. * Return: D0 has to point to ihs to be used when removal proceeds
  514. *      If D0 = 0 then removal is aborted
  515. PSEndIHS1    Push        D1-D2/A0-A1/A6
  516.         Prepare        Exec_Call
  517.         CallLib        Forbid
  518.         lea        ihs_PortName(A0),A1
  519.         CallLib        FindPort
  520.         move.l        D0,D2
  521.         CallLib        Permit
  522.         move.l        D2,D0            ; Does Forbid/Permit destroy scratch-registers ?
  523.         Pop        D1-D2/A0-A1/A6
  524.         rts
  525. * Call:   A0 = ihs
  526. *         D0 = 0 means everything went perfect
  527. *             -1 means something went wrong during removal
  528. PSEndIHS2    Push        D0-D1/A0-A1/A6
  529.         tst.l        D0
  530.         bmi.S        1$
  531.         Prepare        Exec_Call
  532.         move.l        ihs_Length(A0),D0
  533.         move.l        A0,A1
  534.         CallLib        FreeMem
  535. 1$        Pop        D0-D1/A0-A1/A6
  536.         rts
  537.  
  538. * Tries to read hotkeys from file (if any is specified)
  539. * Return: D0 = 0 means failure
  540. GetKeys        Push        D1-D7/A0-A6
  541.         moveq        #1,rtsValue
  542.         tst.l        CLen(DB)
  543.         beq.S        2$
  544.         moveq        #0,rtsValue
  545.         Prepare        Dos_Call
  546.         move.l        CName(DB),D1
  547.         move.l        #MODE_OLDFILE,D2
  548.         CallLib        Open
  549.         move.l        D0,D4
  550.         beq.S        2$
  551.         move.l        D0,D1
  552.         lea        TempFile(PC),A0
  553.         move.l        A0,D2
  554.         move.l        #FilePart,D3
  555.         CallLib        Read
  556.         cmp.l        D0,D3
  557.         bne.S        1$
  558.         movem.l        TempFile(PC),D0-D1
  559.         movem.l        PWKVersionID(PC),D2-D3
  560.         cmp.l        D0,D2
  561.         bne.S        1$
  562.         cmp.l        D1,D3
  563.         bne.S        1$
  564.         lea        TempFile(PC),A0
  565.         lea        PWKVersionID(PC),A1
  566.         move.l        #FilePart,D0
  567.         Call        MemCopy
  568.         moveq        #1,rtsValue
  569. 1$        move.l        D4,D1
  570.         CallLib        Close
  571. 2$        move.l        rtsValue,D0
  572.         Pop        D1-D7/A0-A6
  573.         rts
  574.  
  575. * This is buffer when trying to read file
  576. TempFile    dc.l        'PWKF'
  577.         dc.w        PWKeysVersion,PWKeysRevision
  578.         dc.b        PWKeysPri,0
  579.         dc.w        DefFuncNumber
  580. TemPWKeys    dcb.b        FilePart-12
  581.  
  582. *====================== Input-handler start =========================
  583. ihs_Port    =0
  584. ihs_Interrupt    =MP_SIZE
  585. ihs_ID        =MP_SIZE+IS_SIZE
  586. ihs_Length    =MP_SIZE+IS_SIZE+4
  587. ihs_Flags    =MP_SIZE+IS_SIZE+8
  588. ihs_PortName    =MP_SIZE+IS_SIZE+10
  589.  
  590. ihs_Start    MACRO
  591.         dcb.b        MP_SIZE        ; Message-Port structure
  592.         dcb.b        IS_SIZE        ; Interrupt structure
  593.         dc.l        'P_IH'        ; ID (Handler made by me)
  594.         dc.l        0        ; Length of handler 
  595.         dc.w        0        ; Flags
  596.         dc.b        \1,0
  597.         EVEN
  598.         ENDM
  599.  
  600. HDisabled    =0
  601. HNoExtRemoval    =1                ; Future
  602.  
  603. * This is the handler-block
  604. IHS        ihs_Start    <'PWKeys V1.0 Port'>
  605. * Local variables
  606. Chain        dc.l        0
  607. IntuiBase    dc.l        0
  608. * This is the beginning of the part coming from a file
  609. PWKVersionID    dc.l        'PWKF'
  610. PWKVersionNum    dc.w        PWKeysVersion,PWKeysRevision
  611. PWKPri        dc.b        PWKeysPri,0
  612. PWKHotKeys    dc.w        DefFuncNumber
  613. * These defines are the default when no file is specified
  614. * Keep them sorted on 'Code|Qual'
  615. KeyDefines    HotKey        KP1,LAMIGA,LAMIGA,AW_TO_LEFT_BOTTOM
  616.         HotKey        KP2,LAMIGA,LAMIGA,AW_TO_BOTTOM
  617.         HotKey        KP3,LAMIGA,LAMIGA,AW_TO_RIGHT_BOTTOM
  618.         HotKey        KP4,LAMIGA,LAMIGA,AW_TO_LEFT
  619.         HotKey        KP5,LAMIGA,LAMIGA,AW_TO_CENTER
  620.         HotKey        KP6,LAMIGA,LAMIGA,AW_TO_RIGHT
  621.         HotKey        KP7,LAMIGA,LAMIGA,AW_TO_LEFT_TOP
  622.         HotKey        KP8,LAMIGA,LAMIGA,AW_TO_TOP
  623.         HotKey        KP9,LAMIGA,LAMIGA,AW_TO_RIGHT_TOP
  624.         HotKey        UPARROW,LAMIGA,LSHIFT|LAMIGA|RAMIGA,AW_TO_BACK
  625.         HotKey        UPARROW,LSHIFT|LAMIGA,LSHIFT|LAMIGA|RAMIGA,FRONT_W_TO_BACK
  626.         HotKey        UPARROW,RAMIGA,LSHIFT|LAMIGA|RAMIGA,FRONT_S_TO_BACK
  627.         HotKey        DOWNARROW,LAMIGA,LSHIFT|LAMIGA|RAMIGA,AW_TO_FRONT
  628.         HotKey        DOWNARROW,LSHIFT|LAMIGA,LSHIFT|LAMIGA|RAMIGA,BACK_W_TO_FRONT
  629.         HotKey        DOWNARROW,RAMIGA,LSHIFT|LAMIGA|RAMIGA,BACK_S_TO_FRONT
  630.         HotKey        RIGHTARROW,LAMIGA,LAMIGA,ACTIVATE_NEXT_W
  631.         HotKey        LEFTARROW,LAMIGA,LAMIGA,ACTIVATE_PREV_W
  632.         HotKey        U_CODE,U_QUAL,U_QUAL,U_FUNC
  633.         HotKey        U_CODE,U_QUAL,U_QUAL,U_FUNC
  634.         HotKey        U_CODE,U_QUAL,U_QUAL,U_FUNC
  635. * This is the end of the part coming from a file
  636.  
  637. * This table below defines the connction between the
  638. * selected hotkey and the function to perform
  639. JmpEntry_SIZE    =2
  640. JmpEntry    MACRO
  641.         dc.w        \1-JmpTable
  642.         ENDM
  643. JmpTable    JmpEntry    WindowToTop
  644.         JmpEntry    WindowToBottom
  645.         JmpEntry    WindowToLeft
  646.         JmpEntry    WindowToRight
  647.         JmpEntry    WindowToTL
  648.         JmpEntry    WindowToBL
  649.         JmpEntry    WindowToTR
  650.         JmpEntry    WindowToBR
  651.         JmpEntry    WindowToCenter
  652.         JmpEntry    CurrWinToFront
  653.         JmpEntry    CurrWinToBack
  654.         JmpEntry    ActivatePrevWin
  655.         JmpEntry    ActivateNextWin
  656.         JmpEntry    BackWinToFront
  657.         JmpEntry    FrontWinToBack
  658.         JmpEntry    BackScrToFront
  659.         JmpEntry    FrontScrToBack
  660.         JmpEntry    Dummy
  661.         JmpEntry    Dummy
  662.         JmpEntry    Dummy
  663.  
  664. * Handler()
  665. * This is the input handler.  For each event in the event list:
  666. * If the event is a raw key event, then
  667. *   make the KeyCode longword for that event's code and qualifier,
  668. *   binary search the KeyDefines[] array for a matching entry (only consider
  669. *     the qualifiers specified by the HotKey_Mask).  Since most keys pressed
  670. *     will NOT match a hot-key, we want the search to be as fast as 
  671. *     possible, so we use a binary search rather than a linear search.
  672. * if the key was not a hot key,
  673. *   go on to the next key
  674. * otherwise,
  675. *   perform the function for the specified hot key,
  676. *  remove the hot key from the event list.
  677. * When all the events have been checked, return the event list so that
  678. * Intuition can do its thing.
  679.  
  680. Max        EQUR    D4
  681. Min        EQUR    D5
  682. Num        EQUR    D6
  683. TheKey        EQUR    D7
  684. PEvent        EQUR    A4                ; Previous Event
  685. Event        EQUR    A5                ; This Event
  686.  
  687. Next        =ie_NextEvent
  688. Class        =ie_Class
  689. Code        =ie_Code
  690. Qual        =ie_Qualifier
  691.  
  692. * Call:  A0 = List of InputEvents, A1 = HandlerData
  693. HandlerCode    Push        D1-D7/A0-A6
  694.         move.w        IHS+ihs_Flags(PC),D0
  695.         btst        #HDisabled,D0        ; Future feature
  696.         bne        NoMoreEvents
  697.         lea        Chain(PC),PEvent
  698.         move.l        A0,Next(PEvent)
  699. ieLoop        move.l        Next(PEvent),Event
  700.         move.l        Event,D0
  701.         beq.S        NoMoreEvents
  702.         cmpi.b        #IECLASS_RAWKEY,Class(Event)
  703.         bne.S        DontRemove
  704. DoKey        move.w        Code(Event),TheKey    ; Construct a 'Code|Qual' long-word
  705.         swap        TheKey
  706.         move.w        Qual(Event),TheKey
  707.         move.w        PWKHotKeys(PC),Max    ; Do Binary-search
  708.         moveq        #-1,Min
  709. SearchLoop    move.w        Max,Num
  710.         add.w        Min,Num
  711.         asr.w        #1,Num
  712.         cmp.w        Num,Min
  713.         beq.S        DontRemove        ; Didn't find a match
  714.         move.w        Num,D0
  715.         lsl.w        #3,D0            ; HotKey_SIZE*Num
  716.         lea        KeyDefines(PC),A2
  717.         add.w        D0,A2
  718.         move.l        TheKey,D0
  719.         and.l        HotKey_Mask(A2),D0    ; TheKey & KeyDefines[Num].HotKey_Mask
  720.         cmp.l        HotKey_ID(A2),D0    ; A match ?
  721.         beq.S        Perform
  722.         blt.S        LookLower
  723. LookHigher    move.l        Num,Min            ; (TheKey & KeyDefines[Num].HotKey_Mask) > KeyDefines[Num].HotKey_ID
  724.         bra.S        SearchLoop
  725. LookLower    move.l        Num,Max            ; (TheKey & KeyDefines[Num].HotKey_Mask) < KeyDefines[Num].HotKey_ID
  726.         bra.S        SearchLoop
  727.  
  728. * Found a match
  729. * A2 = Hotkey
  730. Perform        Prepare        Exec_Call
  731.         CallLib        Forbid            ; (TheKey & KeyDefines[Num].HotKey_Mask) = KeyDefines[Num].HotKey_ID
  732.         moveq        #0,D0
  733.         move.b        HotKey_Func(A2),D0    ; KeyDefines[Num].HotKey_Func
  734.         lsl.w        #1,D0            ; JmpEntry_SIZE*KeyDefines[Num].HotKey_Func
  735.         lea        JmpTable(PC),A0
  736.         add.w        0(A0,D0.W),A0
  737.         move.l        IntuiBase(PC),A6    ; Intuitionbase stays loaded
  738.         jsr        (A0)            ; Jump to function
  739.         Prepare        Exec_Call
  740.         CallLib        Permit
  741. Remove        move.l        Next(Event),Next(PEvent); Remove event from chain and move on to next Event
  742.         bra.S        ieLoop
  743. * Didn't find a match
  744. DontRemove    move.l        Event,PEvent        ; Just move on to next Event
  745.         bra.S        ieLoop
  746. * Lets return
  747. NoMoreEvents    Pop        D1-D7/A0-A6
  748.         move.l        Chain(PC),D0        ; Return (shortened ?) chain
  749.         rts
  750.  
  751. ScreenToBack    jmp        _LVOScreenToBack(A6)
  752. ScreenToFront    jmp        _LVOScreenToFront(A6)
  753. WindowToBack    Call        CheckWindow
  754.         bne.S        WinErr
  755.         jmp        _LVOWindowToBack(A6)
  756. WindowToFront    Call        CheckWindow
  757.         bne.S        WinErr
  758.         jmp        _LVOWindowToFront(A6)
  759. ActivateWindow    Call        CheckWindow
  760.         bne.S        WinErr
  761.         jmp        _LVOActivateWindow(A6)
  762. MoveWindow    Call        CheckWindow
  763.         bne.S        WinErr
  764.         jmp        _LVOMoveWindow(A6)
  765. WinErr        rts
  766.  
  767. * Call:   A0 = Window to check
  768. * Return: Z-flag set if no active stringgadget or system-gadget
  769. *      in the window or in any active requester in the window
  770. CheckWindow    Push        D0/A1
  771.         move.l        wd_FirstRequest(A0),D0
  772.         beq.S        TestWin
  773. ReqCLoop    tst.l        D0
  774.         beq.S        WinCEnd
  775.         move.l        D0,A1
  776.         move.w        rq_Flags(A1),D0
  777.         andi.w        #REQACTIVE,D0
  778.         beq.S        NextReq
  779.         move.l        rq_ReqGadget(A1),D0
  780.         bra.S        GadCLoop    ; Found an active requester
  781. NextReq        move.l        rq_OlderRequest(A1),D0
  782.         bra.S        ReqCLoop
  783. TestWin        move.l        wd_FirstGadget(A0),D0
  784. * D0 = Gadgetlist
  785. GadCLoop    tst.l        D0
  786.         beq.S        WinCEnd
  787.         move.l        D0,A1
  788.         move.w        gg_GadgetType(A1),D0
  789.         andi.w        #SYSGADGET,D0
  790.         bne.S        CheckSELECT
  791.         move.w        gg_GadgetType(A1),D0
  792.         andi.w        #STRGADGET,D0
  793.         beq.S        NextGad
  794. CheckSELECT    move.w        gg_Flags(A1),D0
  795.         andi.w        #SELECTED,D0
  796.         beq.S        NextGad
  797.         moveq        #1,D0        ; Window contains an active string-gadget
  798.         bra.S        WinCEnd        ; or an active system-gadget
  799. NextGad        move.l        gg_NextGadget(A1),D0
  800.         bra.S        GadCLoop
  801. WinCEnd        Pop        D0/A1
  802.         rts
  803.  
  804. * TopWindow()
  805. * Find the top window of the specified screen.  Start at the top layer of
  806. * the screen and move backward as long as the layer exists and has no
  807. * window connected to it.  Return the window associated with the final 
  808. * layer, if any.
  809. * Call  : A0 = Screen
  810. * Return: D0 = Window or NULL
  811. TopWindow    move.l        sc_LayerInfo+li_top_layer(A0),A0
  812.         moveq        #0,D0
  813. 1$        move.l        A0,D1
  814.         beq.S        2$
  815.         move.l        lr_Window(A0),D0
  816.         bne.S        2$
  817.         move.l        lr_back(A0),A0
  818.         bra.S        1$
  819. 2$        tst.l        D0
  820.         rts
  821.  
  822. * BottomWindow()
  823. * Find the bottom window of the specified screen.  Start at the top layer
  824. * and as long as the layer exists, go to the next layer back.  If the
  825. * layer has a window attached, consider that to be the bottom window until
  826. * a lower one is found.
  827. * Call  : A0 = Screen
  828. * Return: D0 = Window or NULL
  829. BottomWindow    move.l        sc_LayerInfo+li_top_layer(A0),A0
  830.         moveq        #0,D0
  831. 1$        move.l        A0,D1
  832.         beq.S        3$
  833.         move.l        lr_Window(A0),D1
  834.         beq.S        2$
  835.         move.l        D1,D0
  836. 2$        move.l        lr_back(A0),A0
  837.         bra.S        1$
  838. 3$        tst.l        D0
  839.         rts
  840.  
  841. * NextWindow()
  842. * Find the next window below the specified window (wrap arround to the top
  843. * if the window is the bottom one).  Start with the window's layer and go
  844. * back until a layer with a window is found, or no more layers exist.  If
  845. * a window was found, return it, otherwise, use the top window.
  846. * Call  : A0 = Window
  847. * Return: D0 = Next Window or NULL
  848. NextWindow    move.l        wd_WLayer(A0),A1
  849. 1$        move.l        lr_back(A1),A1
  850.         move.l        A1,D1
  851.         beq.S        2$
  852.         move.l        lr_Window(A1),D0
  853.         beq.S        1$
  854.         bra.S        3$
  855. 2$        move.l        wd_WScreen(A0),A0
  856.         CallS        TopWindow
  857. 3$        tst.l        D0
  858.         rts
  859.  
  860. * PreviousWindow()
  861. * Find the window that is on top of the specified window (or NULL if there
  862. * are no windows above it).  Start with the window's layer, and move to
  863. * the layer in front until a layer with a (different) window is found, or
  864. * until no more layers exist.  If a window was found, return it, otherwise
  865. * return NULL.
  866. * Call  : A0 = Window
  867. * Return: D0 = Previous Window or NULL
  868. PrevWindow    moveq        #0,D0
  869.         move.l        wd_WLayer(A0),A1
  870. 1$        move.l        lr_front(A1),A1
  871.         move.l        A1,D1
  872.         beq.S        2$
  873.         move.l        lr_Window(A1),D0
  874.         beq.S        1$
  875.         cmp.l        A0,D0
  876.         beq.S        1$
  877. 2$        tst.l        D0
  878.         rts
  879.  
  880. * BackScrToFront()
  881. * Bring the bottom-most screen to the top, and activate its top window.
  882. * While there is a screen following the current one, move the the next screen.
  883. * Bring that screen to the front and find its top window.  If one was found,
  884. * activate the window.
  885. BackScrToFront    move.l        A2,-(SP)
  886.         move.l        ib_FirstScreen(A6),A2
  887. 1$        move.l        sc_NextScreen(A2),D0
  888.         beq.S        2$
  889.         move.l        D0,A2
  890.         bra.S        1$
  891. 2$        move.l        A2,A0
  892.         Call        ScreenToFront
  893.         move.l        A2,A0
  894.         move.l        (SP)+,A2
  895.         Call        TopWindow
  896.         bra.S        ActiCommon
  897.  
  898. * FrontScreenToBack()
  899. * Move the top screen to the back and activate the top window on the new
  900. * top screen.
  901. FrontScrToBack    move.l        ib_FirstScreen(A6),A0
  902.         Call        ScreenToBack
  903.         move.l        ib_FirstScreen(A6),A0
  904.         Call        TopWindow
  905.         bra.S        ActiCommon
  906.  
  907. * ActivatePreviousWindow()
  908. * Get the window previous to the current window (if none, then get the
  909. * bottom window in the active screen), and activate that window.
  910. ActivatePrevWin    move.l        ib_ActiveWindow(A6),A0
  911.         CallS        PrevWindow
  912.         bne.S        ActiCommon
  913.         move.l        ib_ActiveScreen(A6),A0
  914.         Call        BottomWindow
  915.         bra.S        ActiCommon
  916.  
  917. * ActivateNextWindow()
  918. * Get the window below the current window and activate it.
  919. ActivateNextWin    move.l        ib_ActiveWindow(A6),A0
  920.         Call        NextWindow
  921. ActiCommon    beq.S        1$
  922.         move.l        D0,A0
  923.         Call        ActivateWindow
  924. 1$        rts
  925.  
  926. * CurrentWindowToBack()
  927. * Send the current window to the back of the list.
  928. CurrWinToBack    move.l        ib_ActiveWindow(A6),D0
  929.         beq.S        1$
  930.         move.l        D0,A0
  931.          Call        WindowToBack
  932. 1$        rts
  933.  
  934. * CurrentWindowToFront()
  935. * Send the current window to the top of the list.
  936. CurrWinToFront    move.l        ib_ActiveWindow(A6),D0
  937.         beq.S        1$
  938.         move.l        D0,A0
  939.         Call        WindowToFront
  940. 1$        rts
  941.  
  942. * BackWindowToFront()
  943. * Move the bottom window to the top and activate it.  Get the bottom window,
  944. * skipping over backdrop windows.  If one is found, bring it to the front,
  945. * and activate it.
  946. BackWinToFront    move.l        A2,-(SP)
  947.         move.l        ib_ActiveScreen(A6),A0
  948.         Call        BottomWindow
  949.         beq.S        3$
  950. 1$        move.l        D0,A0
  951.         move.l        A0,D0
  952.         beq.S        3$
  953.         btst        #0,wd_Flags+2(A0)    ; BackDrop ?
  954.         beq.S        2$
  955.         Call        PrevWindow
  956.         bra.S        1$
  957. 2$        move.l        A0,A2
  958.         Call        WindowToFront
  959.         move.l        A2,D0
  960.         beq.S        3$
  961.         move.l        D0,A0
  962.         Call        ActivateWindow
  963. 3$        move.l        (SP)+,A2
  964.         rts
  965.  
  966. * FrontWindowToBack()
  967. * Move the top window to the back, and activate the new top window.
  968. * Get the top window, and then the window following it.  Send the top window
  969. * to the back, and activate the next window.
  970. FrontWinToBack    Push        D2/A2
  971.         move.l        ib_ActiveScreen(A6),A0
  972.         Call        TopWindow
  973.         beq.S        1$
  974.         move.l        D0,A0
  975.         move.l        A0,A2
  976.         Call        NextWindow
  977.         move.l        D0,D2
  978.         move.l        A2,A0
  979.         Call        WindowToBack
  980.         move.l        D2,D0
  981.         beq.S        1$
  982.         move.l        D0,A0
  983.         Call        ActivateWindow
  984. 1$        Pop        D2/A2
  985.         rts
  986.  
  987. WindowToTop    lea        TopIt(PC),A1        ; Window To Top
  988.         lea        DontMoveX(PC),A2
  989.         bra.S        WindowMove
  990. WindowToBottom    lea        BottomIt(PC),A1        ; Window To Bottom
  991.         lea        DontMoveX(PC),A2
  992.         bra.S        WindowMove
  993. WindowToLeft    lea        DontMoveY(PC),A1    ; Window To Left
  994.         lea        LeftIt(PC),A2
  995.         bra.S        WindowMove
  996. WindowToRight    lea        DontMoveY(PC),A1    ; Window To Right
  997.         lea        RightIt(PC),A2
  998.         bra.S        WindowMove
  999. WindowToCenter    lea        CenterHeight(PC),A1    ; Window To Center
  1000.         lea        CenterWidth(PC),A2
  1001.         bra.S        WindowMove
  1002. WindowToTL    lea        TopIt(PC),A1        ; Window To Upper Left Corner
  1003.         lea        LeftIt(PC),A2
  1004.         bra.S        WindowMove
  1005. WindowToTR    lea        TopIt(PC),A1        ; Window To Upper Right Corner
  1006.         lea        RightIt(PC),A2
  1007.         bra.S        WindowMove
  1008. WindowToBL    lea        BottomIt(PC),A1        ; Window To Lower Left Corner
  1009.         lea        LeftIt(PC),A2
  1010.         bra.S        WindowMove
  1011. WindowToBR    lea        BottomIt(PC),A1        ; Window To Lower Right Corner
  1012.         lea        RightIt(PC),A2
  1013.  
  1014. * A1 = Function to adjust window in y-direction
  1015. * A2 = Function to adjust window in x-direction
  1016. WindowMove    Push        A1
  1017.         move.l        ib_ActiveWindow(A6),A0
  1018.         jsr        (A1)
  1019.         move.w        D0,D1
  1020.         jsr        (A2)
  1021.         bne.S        1$
  1022.         tst.w        D1
  1023.         beq.S        2$
  1024. 1$        Call        MoveWindow
  1025. 2$        Pop        A1
  1026.         rts
  1027.  
  1028. DontMoveX
  1029. DontMoveY    moveq        #0,D0
  1030. Dummy        rts
  1031.  
  1032. * A0=window
  1033. CenterHeight    move.l        wd_WScreen(A0),A1
  1034.         move.w        sc_Height(A1),D0
  1035.         sub.w        wd_Height(A0),D0
  1036.         asr.w        #1,D0
  1037.         sub.w        wd_TopEdge(A0),D0
  1038.         rts
  1039.  
  1040. * A0=window
  1041. CenterWidth    move.l        wd_WScreen(A0),A1
  1042.         move.w        sc_Width(A1),D0
  1043.         sub.w        wd_Width(A0),D0
  1044.         asr.w        #1,D0
  1045.         sub.w        wd_LeftEdge(A0),D0
  1046.         rts
  1047.  
  1048. * A0=window
  1049. BottomIt    move.l        wd_WScreen(A0),A1
  1050.         move.w        sc_Height(A1),D0
  1051.         sub.w        wd_TopEdge(A0),D0
  1052.         sub.w        wd_Height(A0),D0
  1053.         rts
  1054.  
  1055. * A0=window
  1056. RightIt        move.l        wd_WScreen(A0),A1
  1057.         move.w        sc_Width(A1),D0
  1058.         sub.w        wd_LeftEdge(A0),D0
  1059.         sub.w        wd_Width(A0),D0
  1060.         rts
  1061.  
  1062. * A0=window
  1063. TopIt        move.w        wd_TopEdge(A0),D0
  1064.         neg.w        D0
  1065.         rts
  1066.  
  1067. * A0=window
  1068. LeftIt        move.w        wd_LeftEdge(A0),D0
  1069.         neg.w        D0
  1070.         rts
  1071.  
  1072. HandlerSize    =        *-IHS
  1073. *====================== Input-handler end ===========================
  1074.  
  1075. *====================== Data-definition start =======================
  1076.  rStart
  1077.  rLong        CLen
  1078.  rAPtr        CName
  1079.  rAPtr        PProcess
  1080.  rAPtr        WBMsg
  1081.  rAPtr        DosBase
  1082.  rAPtr        IntBase
  1083.  rAPtr        IconBase
  1084.  rAPtr        DiskObj
  1085.  rAPtr        HPort
  1086.  rStorage    IReq,IOSTD_SIZE
  1087.  rStorage    IPort,MP_SIZE
  1088.  rAPtr        HMem
  1089.  rEnd
  1090.  
  1091. DosName        dc.b        'dos.library',0
  1092. IntName        dc.b        'intuition.library',0
  1093. IconName    dc.b        'icon.library',0
  1094. InputName    dc.b        'input.device',0
  1095. FileTxt        dc.b        'FILE',0
  1096.         END
  1097.  
  1098.  --- InputEvent.ie_Class ---
  1099. IECLASS_NULL        0x00    A NOP input event
  1100. IECLASS_RAWKEY        0x01    A raw keycode from the keyboard device
  1101. IECLASS_RAWMOUSE    0x02    The raw mouse report from the game port device
  1102. IECLASS_EVENT        0x03    A private console event
  1103. IECLASS_POINTERPOS    0x04    A Pointer Position report
  1104. IECLASS_TIMER        0x06    A timer event
  1105. IECLASS_GADGETDOWN    0x07    select button pressed down over a Gadget (address in ie_EventAddress)
  1106. IECLASS_GADGETUP    0x08    select button released over the same Gadget (address in ie_EventAddress)
  1107. IECLASS_REQUESTER    0x09    some Requester activity has taken place.  See Codes REQCLEAR and REQSET
  1108. IECLASS_MENULIST    0x0A    this is a Menu Number transmission (Menu number is in ie_Code)
  1109. IECLASS_CLOSEWINDOW    0x0B    User has selected the active Window's Close Gadget
  1110. IECLASS_SIZEWINDOW    0x0C    this Window has a new size
  1111. IECLASS_REFRESHWINDOW    0x0D    the Window pointed to by ie_EventAddress needs to be refreshed
  1112. IECLASS_NEWPREFS    0x0E    new preferences are available
  1113. IECLASS_DISKREMOVED    0x0F    the disk has been removed
  1114. IECLASS_DISKINSERTED    0x10    the disk has been inserted
  1115. IECLASS_ACTIVEWINDOW    0x11    the window is about to be made active
  1116. IECLASS_INACTIVEWINDOW    0x12    the window is about to be made inactive
  1117. IECLASS_MAX        0x12    the last class
  1118.  
  1119.   --- InputEvent.ie_Code --- 
  1120. IECLASS_RAWKEY
  1121. IECODE_UP_PREFIX    0x80
  1122. IECODE_KEY_CODE_FIRST    0x00
  1123. IECODE_KEY_CODE_LAST    0x77
  1124. IECODE_COMM_CODE_FIRST    0x78
  1125. IECODE_COMM_CODE_LAST    0x7F
  1126.   
  1127. IECLASS_ANSI
  1128. IECODE_C0_FIRST        0x00
  1129. IECODE_C0_LAST        0x1F
  1130. IECODE_ASCII_FIRST    0x20
  1131. IECODE_ASCII_LAST    0x7E
  1132. IECODE_ASCII_DEL    0x7F
  1133. IECODE_C1_FIRST        0x80
  1134. IECODE_C1_LAST        0x9F
  1135. IECODE_LATIN1_FIRST    0xA0
  1136. IECODE_LATIN1_LAST    0xFF
  1137.   
  1138. IECLASS_RAWMOUSE
  1139. IECODE_LBUTTON        0x68    also uses IECODE_UP_PREFIX
  1140. IECODE_RBUTTON        0x69
  1141. IECODE_MBUTTON        0x6A
  1142. IECODE_NOBUTTON        0xFF
  1143.   
  1144. IECLASS_EVENT
  1145. IECODE_NEWACTIVE    0x01    active input window changed
  1146.  
  1147. IECLASS_REQUESTER Codes
  1148. REQSET is broadcast when the first Requester (not subsequent ones) opens
  1149. in the Window
  1150.  
  1151. IECODE_REQSET        0x01
  1152. REQCLEAR is broadcast when the last Requester clears out of the Window
  1153. IECODE_REQCLEAR        0x00
  1154.  
  1155.  --- InputEvent.ie_Qualifier ---
  1156. IEQUALIFIER_LSHIFT        0x0001
  1157. IEQUALIFIER_RSHIFT        0x0002
  1158. IEQUALIFIER_CAPSLOCK        0x0004
  1159. IEQUALIFIER_CONTROL        0x0008
  1160. IEQUALIFIER_LALT        0x0010
  1161. IEQUALIFIER_RALT        0x0020
  1162. IEQUALIFIER_LCOMMAND        0x0040
  1163. IEQUALIFIER_RCOMMAND        0x0080
  1164. IEQUALIFIER_NUMERICPAD        0x0100
  1165. IEQUALIFIER_REPEAT        0x0200
  1166. IEQUALIFIER_INTERRUPT        0x0400
  1167. IEQUALIFIER_MULTIBROADCAST    0x0800
  1168. IEQUALIFIER_MIDBUTTON        0x1000
  1169. IEQUALIFIER_RBUTTON        0x2000
  1170. IEQUALIFIER_LEFTBUTTON        0x4000
  1171. IEQUALIFIER_RELATIVEMOUSE    0x8000
  1172.  
  1173. IEQUALIFIERB_LSHIFT        0
  1174. IEQUALIFIERB_RSHIFT        1
  1175. IEQUALIFIERB_CAPSLOCK        2
  1176. IEQUALIFIERB_CONTROL        3
  1177. IEQUALIFIERB_LALT        4
  1178. IEQUALIFIERB_RALT        5
  1179. IEQUALIFIERB_LCOMMAND        6
  1180. IEQUALIFIERB_RCOMMAND        7
  1181. IEQUALIFIERB_NUMERICPAD        8
  1182. IEQUALIFIERB_REPEAT        9
  1183. IEQUALIFIERB_INTERRUPT        10
  1184. IEQUALIFIERB_MULTIBROADCAST    11
  1185. IEQUALIFIERB_MIDBUTTON        12
  1186. IEQUALIFIERB_RBUTTON        13
  1187. IEQUALIFIERB_LEFTBUTTON        14
  1188. IEQUALIFIERB_RELATIVEMOUSE    15
  1189.   
  1190. struct InputEvent
  1191. {
  1192.  struct  InputEvent *ie_NextEvent    ;the chronologically next event
  1193.  UBYTE   ie_Class            ;the input event class
  1194.  UBYTE   ie_SubClass            ;optional subclass of the class
  1195.  UWORD   ie_Code            ;the input event code
  1196.  UWORD   ie_Qualifier            ;qualifiers in effect for the event
  1197.  union
  1198.   {
  1199.    struct
  1200.     {
  1201.      WORD    ie_x            ;the pointer position for the event
  1202.      WORD    ie_y
  1203.     } ie_xy
  1204.    APTR    ie_addr
  1205.   } ie_position
  1206.   struct timeval ie_TimeStamp        ;the system tick at the event
  1207. };
  1208.  
  1209. ie_X            =ie_position.ie_xy.ie_x
  1210. ie_Y            =ie_position.ie_xy.ie_y
  1211. ie_EventAddress        =ie_position.ie_addr
  1212.  
  1213.